package com.wjm.serversocket.test1;

import java.io.File;
import java.net.ServerSocket;
import java.net.Socket;
/**
 * Socket java程序间 上传文件，服务端，不知道能不能支持并发
 */
public class UploadPicServer {

//    public static String fileNameStart = "英雄时刻_20180622-00点17分10s";
    public static String fileMp4 = ".avi";
    public static String fileNameStart = "英雄时刻_20171229-18点54分52s";
//    public static String fileNameStart = "a_100mb";
//    public static String fileMp4 = ".mp4";
    public static String fileName = fileNameStart + fileMp4;
    public static String pcPf = "i:";
    public static String fileStr = pcPf + File.separator + fileNameStart + fileMp4;//文件源-I:\英雄时刻\121965765\英雄时刻_20180622-00点17分10s.avi-564MB
//    public static String fileStr = pcPf + File.separator +"英雄时刻\\121965765\\"+ fileNameStart + fileMp4;//文件源-I:\英雄时刻\121965765\英雄时刻_20180622-00点17分10s.avi-564MB
    public static String ip = "172.16.1.100";
    public static int port = 8888;
    public static String serverfilePath = "server";

    public static void main(String[] args) throws Exception {

        //服务端无法知道传输的文件名，只有通过在开启服务ServerSocket时先用一个http接口获取文件名

//        String fileName = fileName;//这里模拟，假设这个文件名是上一个接口传过来的
        File fileDir = new File(pcPf + File.separator + serverfilePath);//i:\\server
        if (!fileDir.exists()) {
            fileDir.mkdirs();
        }

        ServerSocket serverSocket = new ServerSocket(port);

        while (true) {

            Socket socket = serverSocket.accept();
            new Thread(new UploadTask(fileName, socket)).start();

        }

//        serverSocket.close();
    }
}
